#include "StdAfx.h"
#include "BreakDetector.h"

BreakDetector::BreakDetector()
{
}

BreakDetector::~BreakDetector()
{
}

void BreakDetector::SetIdleThreshold(DWORD dwTicks)
{
	m_dwIdleThreshold = dwTicks;
}

DWORD BreakDetector::GetIdleThreshold() const
{
	return m_dwIdleThreshold;
}

bool BreakDetector::IsOnBreak()
{
	PeriodicUpdate();
	return m_bIsOnBreak;
}

void BreakDetector::PeriodicUpdate()
{
	LASTINPUTINFO info;
	info.cbSize = sizeof(LASTINPUTINFO);
	info.dwTime = 0;
	BOOL bGotInfo = GetLastInputInfo(&info);
	if (bGotInfo)
	{
		DWORD dwElapsed = GetTickCount() - info.dwTime;
		m_bIsOnBreak = dwElapsed > m_dwIdleThreshold;
	}
	else
	{
		ASSERT(0);
	}
}